
/*
    Software License

    Copyright (C) 2021-05-24  Xoronos

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, version 3.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <https://www.gnu.org/licenses/>.
*/

/*
    Liabilities

    The software is provided "AS IS" without any warranty of any kind, either expressed,
    implied, or statutory, including, but not limited to, any warranty that the software
    will conform to specifications, any implied warranties of merchantability, fitness
    for a particular purpose, and freedom from infringement, and any warranty that the
    documentation will conform to the software, or any warranty that the software will
    be error free.

    In no event shall Xoronos be liable for any damages, including, but not limited to,
    direct, indirect, special or consequential damages, arising out of, resulting from,
    or in any way connected with this software, whether or not based upon warranty,
    contract, tort, or otherwise, whether or not injury was sustained by persons or
    property or otherwise, and whether or not loss was sustained from, or arose out of
    the results of, or use of, the software or services provided hereunder.

    To request the provided software under a different license you can contact us at
    support@xoronos.com
*/

#ifndef XORON_CORE_LIB_UTIL_H
#define XORON_CORE_LIB_UTIL_H

#include <stdio.h>
#include "xrn_settings.h"
#include "xrn_common.h"
#include "xrn_core.h"
#include "xrn_arithmetic.h"
#include "xrn_arithmetic_backend.h"

int load_xnum( xnum_t * xnum1,
               uint8_t * crc_bytes,
               xrn_lib_xtype_t * type,
               xrn_lib_xtype_t exp_type, uint8_t * state_size, FILE * fp, xrn_crypto_extra_settings_t settings
 );

int dump_xnum( xnum_t num1,
               xrn_lib_xtype_t type,
               uint8_t crc_bytes, uint8_t state_size, FILE * fp, xrn_crypto_extra_settings_t settings
 );

void gaussian_elimination( xrn_base_t * a
 );

void xor_xrn_matrix( xrn_base_t * a, xrn_base_t * b, xrn_base_t * c
 );

void xor_xrn_vector( xrn_vector_t * a, xrn_vector_t * b, xrn_vector_t * c
 );

void xor_of_bases( xrn_base_t * xb0, xrn_base_t * xb1, xrn_base_t * dst
 );

void xgenesis_base_2_xrn_matrix( xgenesis_base_t * ob, xnum_t * change_of_base, xnum_t * change_of_sign,
                                 xrn_matrix_t * xm
 );

void xgenesis_base_v2m( xgenesis_base_t * obase, xmat_t * dst
 );

void xgenesis_base_m2v( xmat_t * xmat, xgenesis_base_t * dst
 );

void update_xrn_matrix( xrn_matrix_t * src, xrn_matrix_t * dst
 );

void xmatrix_inverse_traverse( xrn_matrix_t * xm, xnum_t * p, xnum_t * d, xnum_t * dst
 );

void const_xmatrix_inverse_traverse( xrn_matrix_t * xm, xnum_t * p, xnum_t * d, xnum_t * dst
 );

void *xmatrix_inverse_traverse_pthread( void *ptr
 );

void *const_xmatrix_inverse_traverse_pthread( void *ptr
 );

void const_distance_eval( xnum_t distance, uint8_t * const_dist
 );

void print_xheader( xrn_crypto_lib_header_t header
 );

int xrn_load_header( xrn_crypto_lib_header_t header,
                     uint8_t * crc_bytes,
                     xrn_lib_xtype_t * type,
                     xrn_lib_xtype_t exp_type,
                     uint8_t * state_size, uint32_t * reserved_0, uint32_t * reserved_1
 );

#endif
